package router

import (
	"fmt"
	"net/http"

	"github.com/gorilla/mux"
)

func NewEchoRouter() *mux.Router {
	router := mux.NewRouter()
	prefix := "/echo"
	subRouter := router.PathPrefix(prefix).Subrouter()
	subRouter.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "{\"message\":\"PONG\"}")
	})
	subRouter.HandleFunc("/{name}", func(w http.ResponseWriter, r *http.Request) {
		pathParams := mux.Vars(r)
		name := pathParams["name"]
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, "{\"message\":\"Hello %s\"}", name)
	})

	return router
}
